package com.example.oj.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.oj.common.Result;
import com.example.oj.entity.Problem;
import com.example.oj.entity.ProblemData;
import com.example.oj.mapper.ProblemDataMapper;
import com.example.oj.service.ProblemDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProblemDataController {

    @Autowired
    private ProblemDataService problemDataService;


    @GetMapping("/problems")
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search){
        Page<ProblemData> problemPage = problemDataService.SelectPage(pageNum, pageSize, search);
        return Result.success(problemPage);
    }

    @GetMapping("/problemdata")
    public Result<?> getProblemData(@RequestParam(value = "id") Integer id){
        ProblemData problemData = problemDataService.getById(id);
        return Result.success(problemData);
    }
}
